<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>商品采购</title>
    <script src="../../../../js/module/jquery-3.4.1.min.js"></script>
</head>
<body>

<blockquote class="layui-elem-quote layui-text">
    合同管理
</blockquote>
<form class="layui-form" action="" lay-filter="example" id="example">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">合同名称</label>
            <div class="layui-input-inline">
                <input type="text" name="htmc"  class="layui-input" id="cgrq">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">合同类型</label>
            <div class="layui-input-inline">
                <input type="text" name="htlx"  class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">合同编号</label>
            <div class="layui-input-inline">
                <input type="text" name="htbh"  class="layui-input" >
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">甲方</label>
            <div class="layui-input-inline">
                <input type="text" name="jf"  class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">乙方</label>
            <div class="layui-input-inline">
                <input type="text" name="yf"  class="layui-input" >
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">资金流向</label>
            <div class="layui-input-inline">
                <input type="text" name="zjlx"  class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">合同状态</label>
            <div class="layui-input-inline">
                <select search-type="htzt" name="htzt">
                    <option value="草稿">草稿</option>
                    <option value="会签">会签</option>
                    <option value="待生效">待生效</option>
                    <option value="履行">履行</option>
                    <option value="归档">归档</option>
                    <option value="作废">作废</option>
                    <option value="已变更">已变更</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">责任人</label>
            <div class="layui-input-inline">
                <input type="text" name="zrr"  class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">签订时间</label>
            <div class="layui-input-inline">
                <input type="text" name="qdsj"  id="qdsj" class="layui-input" placeholder="yyyy-MM-dd">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">合同期限</label>
            <div class="layui-input-inline">
                <input type="number" name="htqx"  class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
                <input type="tel" name="lxdh"  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">金额</label>
            <div class="layui-input-inline">
                <input type="tel" name="je"  class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">合同文件</label>
            <div class="layui-input-inline">
                <input type="text" name="htwj"  id="htwj" class="layui-input layui-hide" >
                <div class="layui-btn-group">
                    <button type="button" class="layui-btn" id="test3">合同上传</button>
                    <button class="layui-btn " id="ckht">查看合同</button>
                </div>
            </div>
        </div>
    </div>




    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" id="reset" class="layui-btn cancels">取消</button>
        </div>
    </div>
</form>
</body>

<script type="text/javascript">
    var dataId = null;
    layui.config({
        base: '../../../../js/module/'
    }).use(['Tool','form', 'layedit', 'laydate',"serviceTools","upload"],function () {
        layui.Tool.init();
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate,
            serviceTools = layui.serviceTools;
        laydate.render({
            elem: '#qdsj'
        });

        //指定允许上传的文件类型
        layui.upload.render({
            elem: '#test3'
            ,url: baseaip+"file/upload"
            ,accept: 'file'
            ,exts: 'doc|docx|pdf'
            ,field:"file"
            ,done: function(res){
                var filePath = res.data;
                filePath = filePath.substring(0,filePath.length - 1 );
                $("#htwj").val("").val(filePath);
            }
        });
        $("#ckht").on("click",function () {
            window.location.href = $("#htwj").val();
            return false;
        })
        $("#reset").on("click", function () {
            window.location.href = "../../../../src/sidewards/base/contract.html";
            return false;
        })

        //监听提交
        form.on('submit(demo1)', function(data){
            var type = localStorage.getItem("type");
            if ( type === null ){
                alert("数据类型不能为空")
            }else{
                var zd = { id:dataId === null ? "" : dataId,
                    type:type,
                    context:JSON.stringify(data.field),
                    keyword:data.field.htmc+"|"+data.field.zrr+"|"+data.field.htzt
                }
                serviceTools.EditOrSaveOrDelete({
                    parame:zd,
                    url:baseaip+"dictionaries/saveOrUpdate",
                    callback:(function(){
                        window.history.back(-2);
                    })()
                })

            }
            return false;
        });

        // console.info(location.href.split("?")[1])
        getHrefId();

    });
    function getHrefId(){
        var loc = location.href;
        console.log(loc);
        var url = loc.split("?")[1];
        console.log(url);
        if(url && url!=''){
            var para = url.split("&");
            var len = para.length;
            var res = {};
            var arr = [];
            for(var i=0;i<len;i++){
                arr = para[i].split("=");
                res[arr[0]] = arr[1];
            }
            dataId = res.id;
            var dataJson = localStorage.getItem([res.id]);
            dataJson != null && dataJson.trim().length > 0 ? (function(){
                data  = JSON.parse(dataJson);
                setForm(data);
            })():"";

        }else{

        }

    }
    function setForm(data){
        layui.use(['form'], function () {
            console.log(data);
            console.log('data');

            layui.form.val('example', JSON.parse(data.context));
        })
    }

</script>

</html>